<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
		<link rel="stylesheet" href="/css/reset.css"/>
		<link rel="stylesheet" href="/css/myStrategyComment.css"/>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/common.js"></script>
		<script>
            $(function () {
				//获取路径中的攻略id
                var params = getParams();
                var star;
                if (params.id) {
                    //根据攻略id查询其常用标签
                    $.get('/strategies/'+params.id+'/tags',function (data) {
                        for(var i =0;i<data.length;i++){
                            data[i].name;
                        }
                        //渲染
                        $(".tag").renderValues({list:data});
                    });
                }
                //星星的点击事件
                $(".star i").click(function () {
					star = $(this).data("star");
                    //console.log(star);
                    var starArr = $(".star i");
                    //console.log(starArr.length);
					//星星选中与未选中的样式
                    for(var i =0;i<starArr.length;i++){
						if(i<star && star){
                            $(starArr[i]).removeClass("fa-star-o").addClass("fa-star");
                        }else{
                            $(starArr[i]).removeClass("fa-star").addClass("fa-star-o");
						}
					}
                });
                //点击的图片上传框
                var rect;
				//给图片框绑定点击事件
                $(".rect").click(function () {
                    rect=$(this);
					$("#fileInput").click();
                });
				//图片选择框的值改变事件
				$("#fileInput").change(function () {
                    if ($(this).val()) {
                        $("#fileForm").ajaxSubmit(function (data) {
                            if (data.status == 1) {
                               rect.html('<img src ="'+data.url+'"/>');
                            }
                        });
                    }
                });
				//禁用数组带 [] 设置
				jQuery.ajaxSettings.traditional = true;

				var json = {};
                $("#submitBtn").click(function () {
					//需要提交的参数
					//星星数量
					json.starNum = star;

					//评价内容
					json.content = $('textarea[name="content"]').val();

					//点评图片
					var imgArr = $(".imgs img");
					var temp ="";
					//循环取出src的值
					for(var i=0;i<imgArr.length;i++){
					    //使用;拼接所有图片的src
					    temp += $(imgArr[i]).attr("src")+";";
					}
					json.imgUrls = temp;
					//选中的系统标签
					var tags = [];
					var child = $(".tag label.active").children();
					var j = 0;
					for(var i = 0;i<child.length;i++){
					    tags[j++] = $(child[i]).val();
					}
					//自定义标签
					//获取用户填的标签值
					var myTags = $("input[name='myTags']").val();
					var arr = myTags.split(" ");
					for(var i =0;i<arr.length;i++){
					    var tag = arr[i];
					    if(tags!=""){
					        tags[j++] = tag;
						}
					}
					//用json 对象存放参数
					json.tags = tags;
					var params = getParams();
					//发送post请求  并且提交参数
					$.post('/strategies/'+params.id+'/comments',json,function (data) {
						window.location.href="/strategyCatalogs.html?id="+params.id;
					});
                });
            });
		</script>
	</head>

	<body>

	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="javascript:window.history.go(-1)">
					<span><i class="fa fa-chevron-left" ></i></span>
				</a>

			</div>
			<div class="col">
				<span>点评</span>
			</div>
			<div class="col"></div>
		</div>
	</div>

	<div class="comment">
		<div class="container star">
			<p>你对该旅游地的评价</p>
			<i class="fa fa-star-o fa-lg" data-star='1' style="color:#fffb53"></i>
			<i class="fa fa-star-o fa-lg" data-star="2" style="color:#fffb53"></i>
			<i class="fa fa-star-o fa-lg" data-star="3" style="color:#fffb53"></i>
			<i class="fa fa-star-o fa-lg" data-star="4" style="color:#fffb53"></i>
			<i class="fa fa-star-o fa-lg" data-star='5' style="color:#fffb53"></i>
		</div>
		<hr/>
		<div class="container tag">
			<p>请为该旅游地选择合适的标签（大家都在评）</p>
			<div class="btn-group-toggle" data-toggle="buttons" render-loop="list">
				<label class="btn btn-outline-danger ">
					<input type="checkbox" autocomplete="off" render-value="list.name"/><span render-html="list.name"></span>
				</label>
				<!--<label class="btn btn-outline-danger">
					<input type="checkbox" autocomplete="off" value="住宿方便"> 住宿方便
				</label>
				<label class="btn btn-outline-danger ">
					<input type="checkbox" autocomplete="off" value="旅游景点多"> 旅游景点多
				</label>
				<label class="btn btn-outline-danger ">
					<input type="checkbox" autocomplete="off" value="适合拍照">适合拍照
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox"  autocomplete="off" value="吃的很多">吃的很多
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox"  autocomplete="off" value="交通不方便">交通不方便
				</label>-->
			</div>

			<p>添加你自己的标签</p>
			<input name="myTags" class="form-control"  placeholder="请使用空格隔开标签，每个标签不超8个字"   />

			<p>更多评价内容</p>
			<textarea name="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
		</div>
		<form id="fileForm" action="/images" method="post" enctype="multipart/form-data">
			<!--隐藏的文件框-->
			<input id="fileInput" name="file" type="file" style="display: none">
		</form>
		<div class="container imgs ">
			<p>上传图片</p>

			<div class="row">
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
			</div>
		</div>

	</div>



	<div class="operation">
		<button class="btn" onclick="window.history.go(-1)">放弃评价</button>
		<button class="btn" id="submitBtn">提交评价</button>
	</div>





	</body>


</html>